package com.guigu.controller.design;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.pojo.design.DLevelFirst;
import com.guigu.pojo.stock.SFirstProductArea;
import com.guigu.service.design.DLevelFirstService;
import com.guigu.service.stock.SFirstProductAreaService;
import com.guigu.utils.CodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mr.Zhang
 * @since 2024-12-17
 */
@Controller
@RequestMapping("/d-level-first")
public class DLevelFirstController {

    @Autowired
    private DLevelFirstService dLevelFirstService;

    @Autowired
    private SFirstProductAreaService sFirstProductAreaService;

    @GetMapping("/initialLevel")
    @ResponseBody
    public ArrayList<DLevelFirst> initialLevel() {
        ArrayList<DLevelFirst> levelFirsts = dLevelFirstService.selectAllLevelFirst();
        return levelFirsts;
    }

    @PostMapping("/insertFirst")
    @ResponseBody
    public Boolean insertFirst(@RequestBody DLevelFirst first){
        DLevelFirst dLevelFirst = dLevelFirstService.selectDLevelFirstOrderByDescOne();
        CodeUtils codeUtils = new CodeUtils();
        String newKindId = codeUtils.getNewKindId(dLevelFirst.getFirstId());
        first.setFirstId(newKindId);
        Boolean b = dLevelFirstService.insertFirst(first);
        //添加I级分类的存储区域
        SFirstProductArea sFirstProductArea = new SFirstProductArea();
        sFirstProductArea.setFirstId(first.getFirstId());
        sFirstProductArea.setFirstName(first.getFirstName());
        Boolean b2 = sFirstProductAreaService.insertSfirstProArea(sFirstProductArea);
        if(b && b2){
            return true;
        }
        return false;
    }

}

